<?php

namespace backend\helpers;

class TicketSalesHelper
{
    public static function generateTicketNumber($str)
    {
        $arr1 = explode(',', $str);
        $arrFinal = [];
        foreach($arr1 as $value)
        {
            if(mb_strlen($value, 'utf-8') <= 8)
            {
                array_push($arrFinal, $value);
            }
            else
            {
                $tempStr = substr($value, 5);
                $tempArr = explode('-', $tempStr);
                if(($tempArr[1] - $tempArr[0]) == 1)
                {
                    array_push($arrFinal, 'ГМ ' . $tempArr[0]);
                    array_push($arrFinal, 'ГМ ' . $tempArr[1]);
                }
                else
                {
                    //количество билетов в интервале
                    $interval = $tempArr[1] - $tempArr[0];
                    array_push($arrFinal, 'ГМ ' . $tempArr[0]);
                    for ($i=1; $i < $interval; $i++) 
                    { 
                        array_push($arrFinal, 'ГМ ' . ($tempArr[0] + $i));
                    }
                    array_push($arrFinal, 'ГМ ' . $tempArr[1]);
                }
            }
        }
        return $arrFinal;
    }
}